/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package demonstration.tab;

import aiaudio.storage.api.RevereUserArtistTuple;
import aiaudio.storage.api.Tuple;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map.Entry;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Nastya
 */
public class DataTableModel extends AbstractTableModel{

    private ArrayList<Entry<RevereUserArtistTuple, Tuple<Double, Double>>> ratings;
    
    public DataTableModel(HashMap<RevereUserArtistTuple, Tuple<Double, Double>> ratings) {
        if(ratings != null){
            this.ratings = new ArrayList<Entry<RevereUserArtistTuple, Tuple<Double, Double>>>();
            this.ratings.addAll(ratings.entrySet());
        }
    }

    
    public int getRowCount() {
        return ratings == null ? 0 : ratings.size();
    }

    public int getColumnCount() {
        return 5;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        if(ratings == null){
            return "";
        }
        Entry<RevereUserArtistTuple, Tuple<Double, Double>> entry = ratings.get(rowIndex);
        switch(columnIndex){
            case 0:
                return entry.getKey().getFirst().toString();
            case 1:
                return entry.getKey().getSecond().toString();
            case 2:
                return Math.abs(entry.getValue().getSecond() - entry.getValue().getFirst());
            case 3:
                return entry.getValue().getFirst();
            case 4:
                return entry.getValue().getSecond();
            default:
                return "";
        }
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        switch(columnIndex){
            case 0:
                return String.class;
            case 1:
                return String.class;
            case 2:
                return Double.class;
            case 3:
                return Double.class;
            case 4:
                return Double.class;
            default:
                return String.class;
        }
    }
    
    
    
}
